﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VWPUserControl.ascx.cs"
    Inherits="CSCV.Group8.BlogRollWebPart.VWP.VWPUserControl" %>
<link href="/_layouts/CSCV.Group8.BlogRollWebPart/css/smoothness/jquery-ui-1.10.1.custom.css"
    rel="stylesheet" />
<script src="/_layouts/CSCV.Group8.BlogRollWebPart/js/jquery-1.9.1.js" type="text/javascript"></script>
<script src="/_layouts/CSCV.Group8.BlogRollWebPart/js/jquery-ui-1.10.1.custom.js"
    type="text/javascript"></script>
<script src="/_layouts/CSCV.Group8.BlogRollWebPart/js/jquery.cookie.js" type="text/javascript"></script>
<link href="/_layouts/CSCV.Group8.BlogRollWebPart/Style/Default.css" type="text/css"
    rel="Stylesheet" />
<script type="text/javascript">
    function pageLoad() {
        $(function () {

            //Get cookie to remember which div is hidden and which is show
            $("#<%=blogrollDiv.ClientID %> .brwp-comment-sub").each(function () {
                //alert(this.id);

                var cookie = $.cookie('show' + this.id);
                if (cookie != null) {
                    if (cookie === 'collapsed') {
                        $(this).hide();
                    }
                    else {
                        $(this).show();
                    }
                }
                else {
                    $(this).hide();
                    $.cookie('show' + this.id, 'collapsed');
                }
            });

            $(" .brwp-image").each(function () {
                var $this = $(this);
                if ($this.attr('tag') === 'Show') {
                    $this.show();
                    $this.parent().find(".brwp-content").css('margin-left', '12%');
                }
                else {
                    $this.hide();
                    $this.parent().find(".brwp-content").css('margin-left', '10px');

                }
            });

            //Add caption to all input by input title
            $('#<%=blogrollDiv.ClientID %> :input[title]').each(function () {
                var $this = $(this);
                if ($this.val() === '') {
                    $this.val($this.attr('title'));
                    $this.css('color', '#B2B2B2');
                }
                $this.focus(function () {
                    if ($this.val() === $this.attr('title')) {
                        $this.val('');
                        $this.css('color', '#000000');
                    }
                });
                $this.blur(function () {
                    if ($this.val() === '') {
                        $this.val($this.attr('title'));
                        $this.css('color', '#B2B2B2');
                    }
                });
            });

            //$('textarea').htmlarea();


            $("#<%=blogrollDiv.ClientID %> .brwp-comment-link").click(function (event) {
                var sender = $(this).parent().parent().parent().find(".brwp-comment-sub");
                sender.slideToggle('slow', function () {
                    // alert(sender.attr('id'));
                    $.cookie('show' + sender.attr('id'), sender.css('display') == 'none' ? 'collapsed' : 'expanded');
                });

                if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }
            });


            $("#947C06DD-79DB-4AB1-8826-497AF7D49623").click(function (event) {
                $(".brwp-main-content").fadeToggle();
                if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }
            });



            $("#<%=blogrollDiv.ClientID %> .brwp-new-comment-button").click(function () {

                var length = $(this).val().split(/\b[\s,\.-:;]*/).length;
                if (length < 1) {
                    alert("Comment cannot be empty and cannot be a number");
                    if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; }
                }
                else {

                    $("#<%=hidPostId.ClientID %>").val($(this).parent().find(".brwp-new-comment-postid").val());
                    $("#<%=hidUrl.ClientID %>").val($(this).parent().find(".brwp-new-comment-spweb").val());

                    var text = $(this).parent().find(".brwp-new-comment-text");
                    if (text.val() != text.attr("title"))
                        $("#<%=hidComment.ClientID %>").val(text.val());
                    //   $("#<%=hidComment.ClientID %>").val(text.htmlarea());
                    else {
                        alert("Comment must not be empty");
                        if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; }
                    }
                    var title = $(this).parent().find(".brwp-new-comment-title");
                    if (title.val() != title.attr("title"))
                        $("#<%=hidTitle.ClientID %>").val(title.val());
                    else {
                        $("#<%=hidTitle.ClientID %>").val("");
                    }

                    $("#<%= btnaddComment.ClientID %>").click();
                    //if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; }
                }


            });



        });
    }
</script>
<div id="blogrollDiv" class="brwp-main-content" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Timer runat="server" ID="timUpdate" Interval="180000">
            </asp:Timer>
            <asp:Repeater ID="rptBlog" runat="server">
                <ItemTemplate>
                    <div class="brwp-post">
                        <div class="brwp-image" runat="server" tag='<%# ((bool)Eval("ShowAvatar")) ? "Show" : "Hide" %>'>
                            <img id="imgUser" class="brwp-image-img" src='<%# DataBinder.Eval(Container.DataItem, "PictureURL") %>'
                                alt="User Picture" />
                        </div>
                        <div class="brwp-content">
                            <div class="brwp-title">
                                <a href='<%# DataBinder.Eval(Container.DataItem,"PostURL") %>'><b>
                                    <%# DataBinder.Eval(Container.DataItem,"Title") %></b> </a>
                            </div>
                            <div class="brwp-body">
                                <%# DataBinder.Eval(Container.DataItem,"Content") %>
                            </div>
                        </div>
                        <div class="brwp-info">
                            <div class="brwp-createby">
                                <asp:Label ID="lblCreateBy" CssClass="brwp-createby-label" Text='<%# DataBinder.Eval(Container.DataItem,"Author") %>'
                                    runat="server" />
                            </div>
                            <div class="brwp-comment">
                                <input type="hidden" class="brwp-comment-postid" value='<%#Eval("PostID") %>' />
                                <a href="#" class="brwp-comment-link">
                                    <img src="/_layouts/CSCV.Group8.BlogRollWebPart/Img/Comment_icon_2.png" alt="Comments"
                                        class="brwp-comment-img" />
                                    <label>
                                        <%#DataBinder.Eval(Container.DataItem, "CommentsCount")%></label>
                                </a>
                            </div>
                            <div class="brwp-created">
                                <asp:Label ID="lblCreated" CssClass="brwp-created-label" Text='<%# DataBinder.Eval(Container.DataItem,"PublishedDate") %>'
                                    runat="server" />
                            </div>
                        </div>
                        <div class="brwp-comment-sub" id='sub_<%# Eval("ID")%>'>
                            <div class="brwp-comment-sub-scroll">
                                <asp:Repeater ID="SubRepeater" runat="server" DataSource='<%# Eval("Comments") %>'>
                                    <ItemTemplate>
                                        <div class="brwp-comment-sub-item">
                                            <div class="brwp-comment-sub-title">
                                                <%# Eval("Title")%></div>
                                            <div class="brwp-comment-sub-date">
                                                <%# Eval("DateCreated")%></div>
                                            <div class="brwp-comment-sub-author">
                                                <%# Eval("Author")%></div>
                                            <div class="brwp-comment-sub-content">
                                                <%# Eval("Contents")%>
                                            </div>
                                        </div>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </div>
                            <div class="brwp-comment-sub-new">
                                <input type="text" title="Insert comment title here ..." class="brwp-new-comment-title clearbox" />
                                <textarea id="txtArea" cols="20" rows="4" class="brwp-new-comment-text clearbox"
                                    title="Insert comment here ..."></textarea>
                                <input type="button" class="brwp-new-comment-button" title="Submit" value="Submit">
                                </button>
                                <input type="text" class="brwp-new-comment-postid hidden" value='<%#Eval("PostID") %>' />
                                <input type="text" class="brwp-new-comment-spweb hidden" value='<%#Eval("PostSPWebUrl") %>' />
                            </div>
                        </div>
                    </div>
                    <div class="brwp-itemfooter">
                    </div>
                </ItemTemplate>
            </asp:Repeater>
            <div id="divHidden" class="hidden">
                <asp:TextBox ID="hidUrl" runat="server" />
                <textarea id="hidComment" runat="server" />
                <asp:TextBox ID="hidTitle" runat="server" />
                <asp:TextBox ID="hidPostId" runat="server" />
                <asp:Button runat="server" ID="btnaddComment" OnClick="btnaddComment_Click" /></div>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>
<div class="brwp-footer" id="947C06DD-79DB-4AB1-8826-497AF7D49623">
    <div class="brwp-left-corner">
    </div>
    <div class="brwp-right-corner">
    </div>
</div>
